package at.tugraz.akm.forume.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import at.tugraz.akm.forume.R;
import at.tugraz.akm.forume.bean.Reply;

public class ReplyAdapter extends ArrayAdapter<Reply> {

	ArrayList<Reply> replies;
	LayoutInflater vi;

	public ReplyAdapter(Context context, int textViewResourceId,
			ArrayList<Reply> objects) {
		super(context, textViewResourceId, objects);
		this.replies = objects;
		vi = (LayoutInflater) getContext().getSystemService(
				Context.LAYOUT_INFLATER_SERVICE);
	}

	public static class ViewHolder {
		public TextView username;
		public TextView date;
		public TextView content;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;

		final ViewHolder holder;

		if (v == null) {
			v = vi.inflate(R.layout.reply_row, null);
			holder = new ViewHolder();
			holder.username = (TextView) v.findViewById(R.id.username);
			holder.date = (TextView) v.findViewById(R.id.date);
			holder.content = (TextView) v.findViewById(R.id.content);
			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}

		final Reply reply = replies.get(position);
		holder.username.setText(reply.getUser());
		holder.date.setText(reply.getDate());
		holder.content.setText(reply.getContent());

		return v;
	}

}
